/*
 * @Author: szx
 * @Date: 2022-04-12 13:46:47
 * @LastEditTime: 2022-04-12 13:50:37
 * @Description:
 * @FilePath: \leetcode\剑指offerII\055\055.js
 */
/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 */
var BSTIterator = function (root) {
    let arr = [];
    const dfs = (root) => {
        root.right && dfs(root.right);
        arr.push(root.val);
        root.left && dfs(root.left);
        return root;
    };
    dfs(root);
    this.arr = arr;
};

/**
 * @return {number}
 */
BSTIterator.prototype.next = function () {
    return this.arr.pop();
};

/**
 * @return {boolean}
 */
BSTIterator.prototype.hasNext = function () {
    return this.arr.length;
};

/**
 * Your BSTIterator object will be instantiated and called as such:
 * var obj = new BSTIterator(root)
 * var param_1 = obj.next()
 * var param_2 = obj.hasNext()
 */
